package com.fc.test.controller.admin;

import com.fc.test.common.base.BaseController;
import com.fc.test.common.domain.AjaxResult;
import com.fc.test.mapper.auto.TAbbMemberMapper;
import com.fc.test.model.auto.AbbPingtai;
import com.fc.test.model.auto.AbbPingtaiExample;
import com.fc.test.model.auto.TAbbMember;
import com.fc.test.model.auto.TAbbOrder;
import com.fc.test.model.custom.TableSplitResult;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.model.custom.TitleVo;
import com.fc.test.service.AbbPingtaiService;
import com.fc.test.service.TAbbCommissionService;
import com.fc.test.service.TAbbOrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("TAbbOrderController")
@Api(value = "")
public class TAbbOrderController extends BaseController{

	private String prefix = "admin/tAbbOrder";
	@Autowired
	private TAbbOrderService tAbbOrderService;



	@GetMapping("view")
	@RequiresPermissions("gen:tAbbOrder:view")
    public String view(Model model)
    {
		String str="";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
        return prefix + "/list";
    }

	@GetMapping("sjview")
	@RequiresPermissions("gen:tAbbOrder:sjview")
	public String sjview(Model model)
	{
		String str="";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
		return prefix + "/sjlist";
	}
	@GetMapping("cxview")
	@RequiresPermissions("gen:tAbbOrder:cxview")
	public String cxview(Model model)
	{
		String str="";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
		return prefix + "/cxlist";
	}

	@GetMapping("sfview")
	@RequiresPermissions("gen:tAbbXiaofei:view")
	public String tAbbXiaofei(Model model)
	{
		String str="";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
		return "admin/tAbbXiaofei" + "/list";
	}

	@PostMapping("list")
	@RequiresPermissions("gen:tAbbOrder:list")
	@ResponseBody
	public Object list(Tablepar tablepar,String searchTxt){
		PageInfo<Map> page=tAbbOrderService.list(tablepar,searchTxt);
		TableSplitResult<Map> result=new TableSplitResult<Map>(page.getPageNum(), page.getTotal(), page.getList());
		return  result;
	}

	@PostMapping("sjlist")
	@RequiresPermissions("gen:tAbbOrder:sjlist")
	@ResponseBody
	public Object sjlist(Tablepar tablepar,String searchTxt,String starttime,String endtime){
		PageInfo<Map> page=tAbbOrderService.list1(tablepar,searchTxt,starttime,endtime) ;
		TableSplitResult<Map> result=new TableSplitResult<Map>(page.getPageNum(), page.getTotal(), page.getList());
		return  result;

	}

	@PostMapping("cxlist")
	@RequiresPermissions("gen:tAbbOrder:cxlist")
	@ResponseBody
	public Object cxlist(Tablepar tablepar,String searchTxt,Integer paystatus,String starttime,String endtime){
		PageInfo<TAbbOrder> page=tAbbOrderService.list2(tablepar,searchTxt,paystatus,starttime,endtime);
		TableSplitResult<TAbbOrder> result=new TableSplitResult<TAbbOrder>(page.getPageNum(), page.getTotal(), page.getList());
		return  result;
	}

	/**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }


	@PostMapping("add")
	@RequiresPermissions("gen:tAbbOrder:add")
	@ResponseBody
	public AjaxResult add(TAbbOrder tAbbOrder,Model model){
		int b=tAbbOrderService.insertSelective(tAbbOrder);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}

	/**
	 * 删除用户
	 * @param ids
	 * @return
	 */
	@PostMapping("remove")
	@RequiresPermissions("gen:tAbbOrder:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=tAbbOrderService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}



	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("TAbbOrder", tAbbOrderService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

	/**
     * 修改保存
     */
    @RequiresPermissions("gen:tAbbOrder:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TAbbOrder record)
    {
        return toAjax(tAbbOrderService.updateByPrimaryKeySelective(record));
    }

	/**
	 * 到店消费
	 */
	@PostMapping("/xiaofei")
	@ResponseBody
	public AjaxResult xiaofei(TAbbOrder record)
	{
        record.setYuliu1("2");
		return toAjax(tAbbOrderService.xiaofei(record));
	}

	/**
	 * 用户消费记录
	 */
	@PostMapping("/memberxiaofei")
	@ResponseBody
	public Object memberxiaofei(Tablepar tablepar,String searchTxt,String starttime,String endtime){

		PageInfo<TAbbOrder> page=tAbbOrderService.memberxiaofei(tablepar,searchTxt,starttime,endtime) ;
		TableSplitResult<TAbbOrder> result=new TableSplitResult<TAbbOrder>(page.getPageNum(), page.getTotal(), page.getList());
		return  result;
	}




}
